template.defaults.imports.splitImages = function (imgsStr) {
    var imgs = imgsStr.split(',');
    template.defaults.imports.imgs = imgs;
};

//下拉刷新
$(".content").pullToRefresh().on("pull-to-refresh", function () {
    $("#list-content").html("");
    resetCondition();
    queryList(function () {
        $(".content").pullToRefreshDone(); // 重置下拉刷新
    });
    return false;
});

//上拉加载更多
$('.content').infinite().on("infinite", function () {
    if (hasNextPage) {
        pageNo++;
        queryList(function () {}, true);
    }
});

//复位所有参数
/* global cate1 resetCate cate2 attrs*/
function resetCondition() {
    pageNo = 1;
}

var loading = false; //状态标记
var hasNextPage = false;
var pageNo = 1;
queryList();
function queryList(callback, isMore) {
    if (loading) return;
    loading = true;
    
    $.post('/antique/api/mallPosts/web/query_list', {
        start: (pageNo - 1) * 20,
        limit: 20,
        token:getCookie('token')
    }, function (result) {
        $('#list-content').append(template('list', {
            list:result.data.list
        }));
        hasNextPage = result.data.hasNextPage;
        if (!result.data.hasNextPage) {
            $('#loadmore').hide();
            $('#nomore').show();
        } else {
            $('#loadmore').show();
            $('#nomore').hide();
        }
        if (callback) callback();
        loading = false;
    });
}

//热推藏品
$.post('/antique/api/mallProduct/web/query_list',{
    queryType:5,
    start:0,
    limit:3
},function(result){
    $('#recomment-content').append(template('recomment-list', {
        list:result.data.list
    }));
});

//热推店铺
$.post('/antique/api/mallShop/web/query_list',{
    queryType:1,
    start:0,
    limit:3,
    showProduct:1
},function(result){
    $('#shop-content').append(template('shop-list', {
        list:result.data.list
    }));
});

//查询热推轮播广告
$.post('/antique/api/mallAdvInfo/web/query_list',{
    type:3,
    start:0,
    limit:5
},function(result){
    $('#productImgs').append(template('productImgs-list', {
        list:result.data.list
    }));
    $(".swiper-container").swiper({
        loop: true
    });
});